<script setup lang="ts">
import { ref } from 'vue';
import { resetSensorPeriodApi } from '@/service/api/businessApi';

interface Emits {
  (e: 'refreshTable'): void;
}

const emit = defineEmits<Emits>();

const visible = ref(false);
const rowData: any = ref({});
const modelSubmit = async () => {
  if (rowData.value.period === '') {
    window.$message?.error('周期参数不能为空');
    return;
  }
  const res: any = await resetSensorPeriodApi({
    id: rowData.value.id,
    period: rowData.value.period
  });
  if (res.error === null) {
    window.$message?.success('重置传感器数据上报周期成功');
    visible.value = false;
    emit('refreshTable');
  }
};

const setRowData = (data: any) => {
  rowData.value = data;
  visible.value = true;
};

defineExpose({
  setRowData
});
</script>

<template>
  <AModal
    v-model:open="visible"
    title="重置周期"
    ok-text="确认"
    cancel-text="取消"
    :width="400"
    :ok-button-props="{ class: 'mt-20px' } as any"
    @ok="modelSubmit"
  >
    <div class="mt-40px flex items-center gap-10px">
      <div class="w-60px">周期:</div>
      <div class="w-100%">
        <AInput v-model:value="rowData.period"></AInput>
      </div>
    </div>
  </AModal>
</template>

<style scoped></style>
